import React, { Component } from 'react';
import BaseComponent from '@/components/BaseComponent';
import styles from './index.less';
import styled from 'styled-components';
import { Spin } from 'antd';
import { connect } from 'dva';

const SignInBox = styled.div`
  margin-top: 25px;
  background-color: #fff;
  border-radius: 5px;
  width: 580px;
  height: 480px;
  display: flex;
  justify-content: center;
  align-items: center;

  .error-message {
    color: #e84637;
    font-size: 14px;
    font-weight: 500;
  }
`;

@connect(({ login, loading }) => ({
  isLoading: loading.effects['login/getToken'],
}))
class GatewayHome extends BaseComponent {
  constructor(props) {
    super(props);
    this.state = {
      message: '',
    };
  }

  componentDidMount() {
    const { location } = this.props;
    const { sessionid } = location.query;
    if (sessionid) {
      this.execHttp('login/getToken', { sessionId: sessionid }).then(resp => {
        const { status, message } = resp;
        if (status === 'error') {
          this.setState({ message });
        }
      });
    } else {
      this.setState({ message: 'session无效，登录失败' });
    }
  }

  render() {
    const { message } = this.state;
    return (
      <div className={styles.gatewayHome}>
        <SignInBox>
          {this.props.isLoading ? <Spin tip="系统初始化中,请稍后..."></Spin> : null}
          {message !== '' ? (
            <div>
              <span className={'error-message'}>{message}</span>
            </div>
          ) : null}
        </SignInBox>
        <div style={{ marginTop: '24px', color: '#fff', fontSize: '12px' }}>
          ©2022 安徽网能云智能科技有限公司. All Rights Reserved.
        </div>
      </div>
    );
  }
}

export default GatewayHome;
